package com.example.redis.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Component;

/**
 * 单个库的key过期事件监听
 *
 * @Author guoyb
 * @Date 2021/7/14  11:06
 */
@Component
@Slf4j
public class RedisKeyExpirationListener implements MessageListener {


    /**
     * redis失效key事件处理
     *
     * @param message
     * @param pattern
     */
    @Override
    public void onMessage(Message message, byte[] pattern) {
        // message.toString()可以获取失效的key
        String expiredKey = message.toString();
        log.info("-------------------");
        log.info("RedisKeyExpirationListener----失效key：" + expiredKey);

        if (expiredKey.startsWith("zeus:order")) {
            //TODO

        }

    }
}